//
//  WmcSaveButton.swift
//  YPWatermarkCamera
//
//  Created by 马涛 on 2022/7/4.
//

import Foundation
import Lottie
import YPBedrock

/// 保存按钮

class WmcPhotoPreviewSaveButton: WmcBaseControl {

    lazy var uploadImgView: UIImageView = {
        let view = UIImageView()
        view.contentMode = .scaleAspectFit
        return view
    }()

    lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.font = 14.yp.uiFont
        label.textColor = UIColor.wmc_white_FFFFFF
        label.textAlignment = .center
        return label
    }()
    
    lazy var lottieView: LottieAnimationView = {
        let animation = LottieAnimation.named("lottle-preview-save", bundle: .WmcBundle)
        let view = LottieAnimationView(animation: animation)
        view.backgroundColor = .clear
        view.animationSpeed = 1
        view.loopMode = .playOnce
        view.isHidden = true
        return view
    }()

    override func makeUI() {
        backgroundColor = UIColor.wmc_mainTheme

        addSubview(uploadImgView)
        addSubview(titleLabel)
        addSubview(lottieView)

        uploadImgView.snp.makeConstraints { make in
            make.top.equalTo(12)
            make.left.right.equalToSuperview()
            make.height.width.equalTo(26)
        }
        
        titleLabel.snp.makeConstraints { make in
            make.top.equalTo(uploadImgView.snp.bottom)
            make.left.right.bottom.equalToSuperview()
        }
        
        lottieView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }
    
    /// 播放动画
    func playAnimation(_ completion: @escaping YPBlock.Empty) {
        lottieView.isHidden = false
        lottieView.play() { [weak self] _ in
            guard let weakSelf = self else { return }
            weakSelf.lottieView.isHidden = false
            completion()
        }
    }
}
